import Taro, { Component } from "@tarojs/taro";
import { Swiper, SwiperItem, Image, View, Text } from "@tarojs/components";
import CommonJs from "../../utils/common";
import "./my.scss";

export default class Index extends Component {
  constructor(props) {
    super(props);
    this.state = {
      amount: "",
      note: "",
      payPassword: "",
      assetTypeId: "",
      mobile: "",
      zjinfo:"",
      monery:'',
      malltype: "",
      issure:0
    };
  }
  config = {
    navigationBarTitleText: "我的转让",
  };
  componentWillMount() {
    this.financeView();
  }

  sure() {
    var vm = this.state;
    if (vm.mobile == "" || vm.mobile == null) {
      CommonJs.msg("输入的手机号不能为空");
      return false;
    }
    if (vm.amount == "" || vm.amount == null) {
      CommonJs.msg("输入的数额不能为空");
      return false;
    }
    if (vm.payPassword == "" || vm.payPassword == null) {
      CommonJs.msg("输入密码不能为空");
      return false;
    }
    var _this = this;
    var url = "/crm/papi/v1.9/currency/userByMobile/" + vm.mobile;
    CommonJs.ajaxRequest(url,"","GET",function(ret) {
      var accountId = ret.data.id;
      var dates = {
        accountId: accountId,
        amount: vm.amount * 100,
        note: vm.note,
        payPassword: vm.payPassword,
        assetTypeId: vm.assetTypeId,
      };
      var url1 = "/crm/papi/v1.9/currency/transferPossession";
      CommonJs.ajaxRequest(url1,dates,"POST",function(res) {
          CommonJs.msg("转让成功");
          setTimeout(function(){
          	CommonJs.open("/pages/my/my");
          },2000)
        },"wfw");
    },"wfw");
   
  }
  financeView() {
    var _this = this;
    var date1 = {};
    // console.log(JSON.stringify(date1)+'date1')
    CommonJs.ajaxRequest("/crm/papi/v1.9/currency/getAcccountCurrency",date1,"GET",function(res) {
        var ret = res.data;
        _this.setState({
        	zjinfo:ret
        },function(){
        	var assetTypeId = _this.$router.preload.regType;
			    var index=0
			    if (assetTypeId == 1) {
			    	index=0
			    } 
			    else if(assetTypeId==7){
			 			index=1
			    }
			    else if(assetTypeId==2){
			      index=2
			    }
			    else if(assetTypeId==5){
			      index=3
			    }
			    else if(assetTypeId==3){
			      index=4
			    }
			    _this.dozy(index)
        });
      },"wfw");
  }
  handleChange(name, e) {
    let value = e.target.value;
    this.setState({
      [name]: value,
    });
  }
  onchange() {
    var _this = this;
    var zjinfo=this.state.zjinfo;
    Taro.showActionSheet({
      itemList: ["UC", "WDT", "共享金", "消费金", "WUC"],
      success: function(res) {
      	var index=res.tapIndex;
        _this.dozy(index)
      },
    });
  }
  dozy(index){
  	var zjinfo=this.state.zjinfo;
  	if (index == 0) {
      var assetTypeId = 1;
      var malltype = "UC";
      var monery=zjinfo.beanBalance
    } 
    else if(index==1){
      var assetTypeId = 7;
      var malltype = "WDT";
      var monery=zjinfo.balanceWdt
    }
    else if(index==2){
      var assetTypeId = 2;
      var malltype = "共享金";
      var monery=zjinfo.balanceGxj
    }
    else if(index==3){
      var assetTypeId = 5;
      var malltype = "消费金";
      var monery=zjinfo.balanceXfj
    }
    else if(index==4){
      var assetTypeId = 3;
      var malltype = "WUC";
      var monery=zjinfo.creditBalance
    }
    this.setState({
      assetTypeId: assetTypeId,
      malltype: malltype,
      monery:monery
    });
  }
  render() {
    return (
      <View className="page">
        <View className="zrcap-list">
          <View className="zr-ul">
            <View className="zr-ol">
              <Text>转让方用户账号</Text>
            </View>
            <View className="zr-li">
              <Input type="text" placeholder="用户手机号码" focus onInput={this.handleChange.bind(this, "mobile")} value={this.state.mobile} />
            </View>
          </View>

          <View className="zr-ul">
            <View className="zr-ol">
              <Text>方式</Text>
            </View>
            <View className="zr-li" onClick={this.onchange.bind(this)}>
              {this.state.malltype}
            </View>
          </View>

          <View className="zr-ul">
            <View className="zr-num">
              <Text>数额</Text>
            </View>
            <View className="zr-nums">
              <Input type="text" placeholder="0.00" focus onInput={this.handleChange.bind(this, "amount")} value={this.state.amount} />
            </View>
          </View>

          <View className="zr-ul">
            <View className="zr-ol">
              <Text>交易密码</Text>
            </View>
            <View className="zr-li">
              <Input type="password" placeholder="请输入交易密码" focus onInput={this.handleChange.bind(this, "payPassword")} value={this.state.payPassword}/>
            </View>
          </View>

          <View className="zrlis">
            <View className="zr-l">{this.state.malltype}余额:</View>
            <View className="zr-value">
              {this.state.monery/100}
            </View>
          </View>

          <View className="zr-btn">
            <View className="zr-sure" onClick={this.sure.bind(this)}>确定</View>
          </View>
        </View>
      </View>
    );
  }
}
